import request from './request'

export interface ProductFilter {
  categoryId?: number
  minPrice?: number
  maxPrice?: number
  keyword?: string
  status?: string
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
  page?: number
  size?: number
}

export interface Product {
  id: number
  name: string
  description: string
  price: number
  originalPrice?: number
  stock: number
  sku: string
  status: string
  mainImage: string
  images: string[]
  category: {
    id: number
    name: string
  }
  brand?: string
  model?: string
  weightKg?: number
  dimensions?: string
  viewCount: number
  soldCount: number
  createdAt: string
  updatedAt: string
}

export interface PageResponse<T> {
  content: T[]
  totalElements: number
  totalPages: number
  size: number
  number: number
  first: boolean
  last: boolean
}

// 获取商品列表
export const getProducts = (params?: any) => {
  return request({
    url: '/products',
    method: 'get',
    params
  })
}

// 根据ID获取商品
export const getProductById = (id: number) => {
  return request({
    url: `/products/${id}`,
    method: 'get'
  })
}

// 创建商品
export const createProduct = (data: any) => {
  return request({
    url: '/products',
    method: 'post',
    data
  })
}

// 更新商品
export const updateProduct = (id: number, data: any) => {
  return request({
    url: `/products/${id}`,
    method: 'put',
    data
  })
}

// 删除商品
export const deleteProduct = (id: number) => {
  return request({
    url: `/products/${id}`,
    method: 'delete'
  })
}

// 获取热门商品
export const getHotProducts = () => {
  return request({
    url: '/products/hot',
    method: 'get'
  })
}

// 获取最新商品
export const getNewProducts = () => {
  return request({
    url: '/products/new',
    method: 'get'
  })
}

// 获取推荐商品
export const getRecommendedProducts = () => {
  return request({
    url: '/products/recommended',
    method: 'get'
  })
}

// 根据分类获取商品
export const getProductsByCategory = (categoryId: number, params?: any) => {
  return request({
    url: `/products`,
    method: 'get',
    params: {
      categoryId,
      ...params
    }
  })
} 